home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Adobe Graphics & Publishing SDK 1996 December
/
Adobe Graphics & Publishing SDK 1996 December.iso
/
mac
/
After Effects 3.1 SDK Mac
/
Examples
/
Effects Samples
/
Resizer
/
Resizer.c
< prev
Wrap
Text File
|
1996-11-06
|
9KB
|
326 lines
/**
Resizer.c
Part of the Adobe After Effects 3.1 SDK.
(c) 1994-96, Adobe Systems Inc, All Rights Reserved.
This effect draws a border of user-specified color and width around
the edges of a layer, resizing the output in the process.
The effect also provides a checkbox to turn on and off the code that
compensates for the downsample factor.
This demonstrates:
Using a Slider control.
Using a Color control.
Using a Checkbox control.
Using the PF_COPY callback routine.
Using the PF_FILL callback routine.
Writing an effect whose output is larger than its input.
Honoring the downsample factors to create correct output at
decreased resolution.
Revision History
1.0, created by dmw, 14 Jan 94
1.1, updated for Mac/Power Mac, dmw, 13 Oct 94
2.0, updated for AE 3.0, dmw
2.1, Added call to AEFX_CLR_STRUCT macro to clear out PF_ParamDef, ba, 6 Nov 96
**/
#include "AE_EffectCB.h"
#include "AE_Macros.h"
#include <A4Stuff.h>
/**
** Here we #define our version values for use in the PF_VERSION
** macro. After Effects uses these values to determine which
** plug-in to run if it finds multiple version of the same effect
** on the user's drive.
**
**/
#define MAJOR_VERSION 2
#define MINOR_VERSION 0
#define BUG_VERSION 0
#define STAGE_VERSION PF_Stage_RELEASE
#define BUILD_VERSION 0
/**
** Some more useful #define's
**
**/
#define NAME "Resizer"
#define DESCRIPTION "Demonstrate Output Buffer Resizing"
/** Parameter Definition Constants
Here we define the parameters, their default
settings, and minimum and maximum values.
**/
enum {
RESIZE_INPUT = 0,
RESIZE_AMOUNT,
RESIZE_COLOR,
RESIZE_DOWNSAMPLE,
RESIZE_NUM_PARAMS
};
#define RESIZE_AMOUNT_MIN 0
#define RESIZE_AMOUNT_MAX 100;
#define RESIZE_AMOUNT_DFLT 0;
/** Command Specific Subroutines
This plug-in only deals with the commands:
PF_Cmd_ABOUT
PF_Cmd_GLOBAL_SETUP
PF_Cmd_PARAMS_SETUP
PF_Cmd_FRAME_SETUP
PF_Cmd_RENDER
All other commands are ignored. There is a routine for
each command, and a main routine to dispatch at the bottom.
There is no PF_Cmd_GLOBAL_SETDOWN because I don't allocate
any memory in GLOBAL_SETUP, so I don't have any cleanup to do.
**/
static PF_Err About (
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output )
{
PF_SPRINTF(out_data->return_msg,
"%s, v%d.%d\r%s",
NAME, MAJOR_VERSION, MINOR_VERSION, DESCRIPTION);
return PF_Err_NONE;
}
static PF_Err GlobalSetup (
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output )
{
PF_Err err = PF_Err_NONE;
/* Need to let AE know what version of the "Resizer" plug-in
* we are.
*/
out_data->my_version = PF_VERSION(MAJOR_VERSION, MINOR_VERSION,
BUG_VERSION, STAGE_VERSION, BUILD_VERSION);
/* This effect resizes its output buffer to be larger, so we should let
* After Effects know that.
*/
out_data->out_flags |= PF_OutFlag_I_EXPAND_BUFFER;
return err;
}
static PF_Err ParamsSetup (
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output )
{
PF_Err err = PF_Err_NONE;
PF_ParamDef def; /* scratch space for a parameter definition */
PF_Pixel white = {255, 255, 255, 255};
char *checkbox_string = "Correct At All Resolutions";
/* Always clear out the PF_ParamDef structure before adding your parameters,
* this macro will do that. */
AEFX_CLR_STRUCT(def);
/* Create the SLIDER parameter... */
def.param_type = PF_Param_SLIDER;
PF_STRCPY(def.name, "Resize Amount (pixels)");
def.flags = def.ui_flags = def.ui_width = def.ui_height = 0; /* clear these to avoid trouble */
def.u.sd.value_str[0] = '\0'; /* set these to be empty to avoid garbage strings */
def.u.sd.value_desc[0] = '\0';
/* The min and max values of the slider and the min and max
* values the user can type will be the same value... */
def.u.sd.valid_min = def.u.sd.slider_min = RESIZE_AMOUNT_MIN;
def.u.sd.valid_max = def.u.sd.slider_max = RESIZE_AMOUNT_MAX;
def.u.sd.value = def.u.sd.dephault = RESIZE_AMOUNT_DFLT;
if (err = PF_ADD_PARAM(in_data, -1, &def)) return err;
/* Create the COLOR parameter... */
AEFX_CLR_STRUCT(def);
def.param_type = PF_Param_COLOR;
def.flags = 0;
PF_STRCPY(def.name, "Resized Area Color");
def.u.cd.dephault = def.u.cd.value = white;
if (err = PF_ADD_PARAM(in_data, -1, &def)) return err;
/* Create the CHECKBOX parameter... */
AEFX_CLR_STRUCT(def);
def.param_type = PF_Param_CHECKBOX;
def.flags = 0;
PF_STRCPY(def.name, "Use Downsample Factors");
def.u.bd.value = def.u.bd.dephault = FALSE;
def.u.bd.u.nameptr = checkbox_string; /* this is strictly a pointer; don't
* STRCPY into it! */
if (err = PF_ADD_PARAM(in_data, -1, &def)) return err;
out_data->num_params = RESIZE_NUM_PARAMS;
return err;
}
static PF_Err FrameSetup (
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output )
{
long border = params[RESIZE_AMOUNT]->u.sd.value;
long border_x, border_y;
if (params[RESIZE_DOWNSAMPLE]->u.bd.value) {
/* Need to shrink the border to accomodate decreased resolutions! You
* should do this with any pixel-valued parameter.
*
* Note that we're looking at the value of the DOWNSAMPLE checkbox parameter
* to decide whether or not to honor downsample sample. You should always do this...
* the checkbox is provided for illustration purposes.
*/
border_x = border * (in_data->downsample_x.num/(double)in_data->downsample_x.den);
border_y = border * (in_data->downsample_y.num/(double)in_data->downsample_y.den);
} else {
/* Let's see what happens when we don't bother with the downsample factor */
border_x = border_y = border;
}
/* add 2 times the border width and height to the input width and
* height to get the final output size. (The border will appear on
* the left and the right */
out_data->width = 2*border_x + params[0]->u.ld.width;
out_data->height = 2*border_y + params[0]->u.ld.height;
/* Tell After Effects that the origin of the input buffer corresponds to
* the (border_x, border_y) pixel in the output buffer. This effectively
* shifts the output layer up and to the left by (border_x, border_y)
*/
out_data->origin.h = border_x;
out_data->origin.v = border_y;
return PF_Err_NONE;
}
static PF_Err Render (
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output )
{
PF_Err err = PF_Err_NONE;
PF_Pixel color;
Rect dst_r;
long border = params[RESIZE_AMOUNT]->u.sd.value;
long border_x, border_y;
if (params[RESIZE_DOWNSAMPLE]->u.bd.value) {
/* Need to shrink the border to accomodate decreased resolutions! You
* should do this with any pixel-valued parameter.
*
* Note that we're looking at the value of the DOWNSAMPLE checkbox parameter
* to decide whether or not to honor downsample sample. You should always do this...
* the checkbox is provided for illustration purposes.
*/
border_x = border * (in_data->downsample_x.num/(double)in_data->downsample_x.den);
border_y = border * (in_data->downsample_y.num/(double)in_data->downsample_y.den);
} else {
/* Let's see what happens when we don't bother with the downsample factor */
border_x = border_y = border;
}
/* get the color parameter */
color = params[RESIZE_COLOR]->u.cd.value;
/* first fill the entire output buffer with the chosen color */
err = PF_FILL(&color, NULL, output);
if (!err) {
/* set up the destination rectangle to be centered in the output buffer. */
dst_r.left = border_x;
dst_r.top = border_y;
dst_r.right = dst_r.left + params[0]->u.ld.width;
dst_r.bottom = dst_r.top + params[0]->u.ld.height;
/* now copy the entire input layer (pass NULL as the rect for the whole
* layer) to the dst_r rectangle in the output buffer.
*/
err = PF_COPY(¶ms[RESIZE_INPUT]->u.ld, output, NULL, &dst_r);
}
return err;
}
PF_Err main (
PF_Cmd cmd,
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output )
{
PF_Err err = PF_Err_NONE;
EnterCodeResource(); /* this only works in Metrowerks */
switch (cmd) {
case PF_Cmd_ABOUT:
err = About(in_data,out_data,params,output);
break;
case PF_Cmd_GLOBAL_SETUP:
err = GlobalSetup(in_data,out_data,params,output);
break;
case PF_Cmd_PARAMS_SETUP:
err = ParamsSetup(in_data,out_data,params,output);
break;
case PF_Cmd_FRAME_SETUP:
err = FrameSetup(in_data,out_data,params,output);
break;
case PF_Cmd_RENDER:
err = Render(in_data,out_data,params,output);
break;
}
ExitCodeResource();
return err;
}